home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTEDIT.SWG / 0009_Write String in ASM.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  999b  |  33 lines

  1. {
  2. BRIAN PAPE
  3.  
  4. Ok, I was writing a little program that I was trying to make as small as
  5. possible, so I wrote this little WriteString function.  Since I'm not an
  6. assembly language mogul by any stretch of the imagination, could one of
  7. you assembly wizards out there tell me if this is Ok.  I mean, it works
  8. fine (and saves almost 1k over linking in the writeln code), but I want
  9. to make sure that I'm not trashing a register or something that needs to
  10. be preserved.  Thanks...  BTW, anybody, go ahead and use it if it
  11. doesn't crash!
  12. }
  13.  
  14. procedure WriteString(s : string); assembler;
  15. asm
  16.   push ds
  17.   mov  ah, 40h    { DOS fcn call 40h write string to file handle }
  18.  
  19.   mov  dx, seg s
  20.   mov  ds, dx
  21.   mov  bx, offset s
  22.  
  23.   mov  dx, bx     { now put the offset into dx for the fcn call }
  24.   inc  dx         { plus 1, to avoid the length byte }
  25.   mov  cl, [bx]   { cl is length to write }
  26.   xor  ch, ch
  27.  
  28.   mov  bx, 1      { file handle to write to }
  29.   int  21h
  30.   pop  ds
  31. end;
  32.  
  33.